# coding=utf-8
import hashlib
import time
import json
import requests


class Crontab(object):
    """
    """

    def __init__(self):
        """
        """
        self.host = "http://127.0.0.1"
        self.port = 10000
        self.uri = '/internal/v1/'
        self.url = '%s:%s%s' % (self.host, self.port, self.uri)
        self.app_version = '6.6'
        self.secretKey = 'alive-dev-2018'

    def run(self):
        """
        """
        cmdid = 10903

        headers = {
            "AppVersion": self.app_version,
            "Timestamp": str(int(time.time() * 1000)),
            "SignType": 'V1',
            "RequestSign": '',
            'cmdId': str(cmdid)
        }

        body = {
            "common": {
                'userId': 0,
                'cmdId': cmdid,
                'release': 1,
                'platform': 2,
                'sessionId': 'dc9bdf62a5e611e8abaa02aa86e00ac4',
                'userKey': '49341723a44c11e8abaa02aa86e00ac4'
            },
            "params": {

            }
        }

        body = json.dumps(body)
        sign_str = '''AppVersion=%s&Body=%s&SignType=V1&Timestamp=%s&secretKey=%s''' \
                   % (self.app_version, body, headers['Timestamp'], self.secretKey)

        headers['RequestSign'] = hashlib.md5(sign_str.encode()).hexdigest().upper()
        res = requests.post(self.url, data=body, headers=headers)


if __name__ == '__main__':
    Crontab().run()
